package com.logistics.utils.webservice.model;

import com.alibaba.fastjson.JSONObject;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import java.io.Serializable;

@Data
@XmlRootElement(name="RESULT")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={"code", "message","data",})
public class WebServiceResponse implements Serializable {

    private String code;
    private String message;
    private String data;

    public WebServiceResponse(){}

    public WebServiceResponse(String code, String message, Object data){
        this.code = code;
        this.message = message;
        this.data = StringUtils.isNotNull(data) ? JSONObject.toJSONString(data) : "";
    }

    public static <T> WebServiceResponse build(String code, String message, Object data){
       return new WebServiceResponse(code, message, data);
    }
}
